﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using HousingInfo.Library;

namespace WebHousingInfo
{
    public partial class dangtin_duan : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                getcategory();
                if (Session["UserName"] == null)
                    Response.Redirect("DangNhap.aspx");
            }

        }

        protected void btndangtin_Click(object sender, EventArgs e)
        {
            ProjectBO project = ProjectBO.NewProjectBO();
            if (Session["UserName"] == null)
                Response.Redirect("DangNhap.aspx");
            else
                project.UserName = Session["UserName"].ToString();
            project.Name = txtname.Text.Trim();
            project.CategoryID = Convert.ToInt32(dlloaiduan.SelectedValue);
            project.Description = txtmota.Text.Trim();
            project.CreatedDate = DateTime.Now;
            project.Address = txtaddress.Text.Trim();
            project.Sure = txtsure.Text.Trim();
            project.NumberFloor = txtsotang.Text.Trim();
            project.Investors = txtdautu.Text.Trim();
            project.Construction = txtthicong.Text.Trim();
            project.Design = txtthietke.Text.Trim();
            project.Scale = txtquimo.Text.Trim();
            project.ContentProject = txtchitiet.Text.Trim();
            if (OptionBO.GetNameOptionBO("tudongduyettinduan").OptionValue == "True")
                project.IsActive = true;
            else
                project.IsActive = false; ;
            try
            {
                project.Save();
                Response.Redirect("du_an.aspx");
            }
            catch
            {
                ScriptManager.RegisterStartupScript(Page, Page.GetType(), "Success",
                                                                    "alert('Đăng dự án thất bại. Vui lòng thử lại.')", true);
            }
        }

        protected void btnhuy_Click(object sender, EventArgs e)
        {
            Response.Redirect("Home.aspx");
        }

        public void getcategory()
        {
            try
            {
                var category = CategoryInfo.GetCategoryInfo_BySingle(false, false, true, false, true);
                dlloaiduan.DataSource = category;
                dlloaiduan.DataBind();
            }
            catch { }
        }

    }
}
